package com.ght.springboot.api;

import com.ght.springboot.api.form.CommentForm;
import com.ght.springboot.api.query.CommentQuery;
import com.ght.springboot.api.query.ElasticSearchQuery;
import com.ght.springboot.service.EsServcie;
import com.ght.springboot.vo.CommentBookVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: haitao.gao
 * @create: 2019-02-17 19:05
 **/
@Api(value = "Elasticsearch", description = "数据搜索", produces = MediaType.APPLICATION_JSON_VALUE)
@RestController(value = "订单基本API")
@RequestMapping(value = "/v1/elasticsearch")
public class EsForLoveController {

    @Autowired
    private EsServcie esServcie;

    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    @ApiOperation(value = "插入评论")
    public String insertComment(@RequestBody(required = true)CommentForm commentForm){

        String result = esServcie.insertComment(commentForm);
        return result;
    }

    @RequestMapping(value = "/query",method = RequestMethod.POST)
    @ApiOperation(value = "查询")
    public List<CommentBookVo> queryComment(@RequestBody CommentQuery query,
                                            @RequestParam("index") String index,
                                            @RequestParam("type") String type){

        List<CommentBookVo> voList = esServcie.queryComment(query,index,type);
        return voList;
    }

    @RequestMapping(value = "/createIndex",method = RequestMethod.POST)
    @ApiOperation(value = "创建索引")
    public String createIndex(){

        String result= esServcie.createIndex();
        return result;
    }
}
